package com.qmth.gkwb.data.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;

import com.qmth.gkwb.data.constant.SignStatus;
import com.qmth.gkwb.data.document.BaseDoc;
import com.qmth.gkwb.data.document.Direct;
import com.qmth.gkwb.data.document.Education;
import com.qmth.gkwb.data.document.Family;
import com.qmth.gkwb.data.document.Spec;

@Document(collection="students")
public class Student {

	@Id
	private String id;
	private String examId;
	private String name;
	private String certino;
	private int gender;
	private BaseDoc nation;
	private BaseDoc polity;
	private BaseDoc graduation;
	private BaseDoc gradeSchool;
	private BaseDoc gradeSchoolCity;
	private String teacher;
	private String special;
	private String honor;
	private String birth;
	private String stuID;
	private String zipcode;
	private String receive;
	private String address;
	
	
	private BaseDoc gradeSchoolRegion;
	private BaseDoc signPoint;
	private BaseDoc grade;
	private BaseDoc schoolClass;
	private BaseDoc stuType;
	private BaseDoc foreign;
	private BaseDoc spokenType;
	private BaseDoc censusProv;
	private BaseDoc censusCity;
	private BaseDoc censusRegion;
	private BaseDoc subject;
	private String subjectType;
	private BaseDoc examType;
	private BaseDoc sport;
	private Long periodId;
	private Integer sportSigned;
	private List<Education> edu = new ArrayList<Education>();
	private List<Family> family = new ArrayList<Family>();
	private List<Spec> arts = new ArrayList<Spec>();
	
	private Date regDate;
	private String password;
	
	private boolean isReg;
	private boolean isSyc;
	
	@Transient
	private SignStatus status;
	
	@Transient
	private int bill = 0;
	@Transient
	private String signString;
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getExamId() {
		return examId;
	}
	public void setExamId(String examId) {
		this.examId = examId;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public BaseDoc getNation() {
		return nation;
	}
	public void setNation(BaseDoc nation) {
		this.nation = nation;
	}
	public String getCertino() {
		return certino;
	}
	public void setCertino(String certino) {
		this.certino = certino;
	}
	
	public Long getPeriodId() {
		return periodId;
	}
	public void setPeriodId(Long periodId) {
		this.periodId = periodId;
	}
	public int getGender() {
		return gender;
	}
	public void setGender(int gender) {
		this.gender = gender;
	}
	public BaseDoc getPolity() {
		return polity;
	}
	public void setPolity(BaseDoc polity) {
		this.polity = polity;
	}
	public BaseDoc getGraduation() {
		return graduation;
	}
	public void setGraduation(BaseDoc graduation) {
		this.graduation = graduation;
	}
	public BaseDoc getGradeSchool() {
		return gradeSchool;
	}
	public void setGradeSchool(BaseDoc gradeSchool) {
		this.gradeSchool = gradeSchool;
	}
	public BaseDoc getGradeSchoolCity() {
		return gradeSchoolCity;
	}
	public void setGradeSchoolCity(BaseDoc gradeSchoolCity) {
		this.gradeSchoolCity = gradeSchoolCity;
	}
	public String getTeacher() {
		return teacher;
	}
	public void setTeacher(String teacher) {
		this.teacher = teacher;
	}
	public String getSpecial() {
		return special;
	}
	public void setSpecial(String special) {
		this.special = special;
	}
	public String getHonor() {
		return honor;
	}
	public void setHonor(String honor) {
		this.honor = honor;
	}
	public String getBirth() {
		return birth;
	}
	public void setBirth(String birth) {
		this.birth = birth;
	}
	public String getStuID() {
		return stuID;
	}
	public void setStuID(String stuID) {
		this.stuID = stuID;
	}
	public String getZipcode() {
		return zipcode;
	}
	public void setZipcode(String zipcode) {
		this.zipcode = zipcode;
	}
	public String getReceive() {
		return receive;
	}
	public void setReceive(String receive) {
		this.receive = receive;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public BaseDoc getGradeSchoolRegion() {
		return gradeSchoolRegion;
	}
	public void setGradeSchoolRegion(BaseDoc gradeSchoolRegion) {
		this.gradeSchoolRegion = gradeSchoolRegion;
	}
	public BaseDoc getSignPoint() {
		return signPoint;
	}
	public void setSignPoint(BaseDoc signPoint) {
		this.signPoint = signPoint;
	}
	public BaseDoc getGrade() {
		return grade;
	}
	public void setGrade(BaseDoc grade) {
		this.grade = grade;
	}
	public BaseDoc getSchoolClass() {
		return schoolClass;
	}
	public void setSchoolClass(BaseDoc schoolClass) {
		this.schoolClass = schoolClass;
	}
	public BaseDoc getStuType() {
		return stuType;
	}
	public void setStuType(BaseDoc stuType) {
		this.stuType = stuType;
	}
	public BaseDoc getForeign() {
		return foreign;
	}
	public void setForeign(BaseDoc foreign) {
		this.foreign = foreign;
	}
	public BaseDoc getSpokenType() {
		return spokenType;
	}
	public void setSpokenType(BaseDoc spokenType) {
		this.spokenType = spokenType;
	}
	public BaseDoc getCensusProv() {
		return censusProv;
	}
	public void setCensusProv(BaseDoc censusProv) {
		this.censusProv = censusProv;
	}
	public BaseDoc getCensusCity() {
		return censusCity;
	}
	public void setCensusCity(BaseDoc censusCity) {
		this.censusCity = censusCity;
	}
	public BaseDoc getCensusRegion() {
		return censusRegion;
	}
	public void setCensusRegion(BaseDoc censusRegion) {
		this.censusRegion = censusRegion;
	}
	public BaseDoc getSubject() {
		return subject;
	}
	public void setSubject(BaseDoc subject) {
		this.subject = subject;
	}
	public String getSubjectType() {
		return subjectType;
	}
	public void setSubjectType(String subjectType) {
		this.subjectType = subjectType;
	}
	public BaseDoc getExamType() {
		return examType;
	}
	public void setExamType(BaseDoc examType) {
		this.examType = examType;
	}
	public BaseDoc getSport() {
		return sport;
	}
	public void setSport(BaseDoc sport) {
		this.sport = sport;
	}
	public Integer getSportSigned() {
		return sportSigned;
	}
	public void setSportSigned(Integer sportSigned) {
		this.sportSigned = sportSigned;
	}
	public List<Education> getEdu() {
		return edu;
	}
	public void setEdu(List<Education> edu) {
		this.edu = edu;
	}
	public List<Family> getFamily() {
		return family;
	}
	public void setFamily(List<Family> family) {
		this.family = family;
	}
	public List<Spec> getArts() {
		return arts;
	}
	public void setArts(List<Spec> arts) {
		this.arts = arts;
	}
	public Date getRegDate() {
		return regDate;
	}
	public void setRegDate(Date regDate) {
		this.regDate = regDate;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public boolean getIsReg() {
		return isReg;
	}
	public void setIsReg(boolean isReg) {
		this.isReg = isReg;
	}
	public boolean getIsSyc() {
		return isSyc;
	}
	public void setIsSyc(boolean isSyc) {
		this.isSyc = isSyc;
	}
	
	public void addEducation(Education edu){
		this.edu.add(edu);
	}
	
	public void addFamily(Family fami){
		this.family.add(fami);
	}
	public int getBill() {
		bill = 0;
		for(Spec s : this.arts){
			if(s.getIsEnabled() && s.getCost() > 0){
				bill += s.getCost();
			}
		}
		
		if(this.sportSigned != null && this.sport != null && this.sportSigned == 1){
			if(this.sport.getId() == 3){
				bill = 210;
			}
			else{
				bill = 175;
			}
		}
		return bill;
	}
	
	public void setReg(boolean isReg) {
		this.isReg = isReg;
	}
	public void setSyc(boolean isSyc) {
		this.isSyc = isSyc;
	}
	public SignStatus getStatus() {
		return status;
	}
	public void setStatus(SignStatus status) {
		this.status = status;
	}
	
	public String getSignString(){
		StringBuilder sb = new StringBuilder();
		
		if(this.arts != null && this.arts.size() > 0){
			for(Spec s : this.arts){
				if(s.getIsEnabled()){
					sb.append(s.getId()+"=");
				}
				if(s.getId() == 4 && s.getIsEnabled()){
					for(Direct doc : s.getDirects()){
						if(doc.getIsEnabled())
						sb.append(doc.getId());
						
					}
					sb.append("=");
				}
			}
		}
		else if(this.sportSigned != null){
			sb.append(this.sportSigned);
			if(this.sportSigned == 1 && this.sport != null){
				sb.append("="+this.sport.getId());
			}
			sb.append("=");
		}
		String str = sb.length() == 0?null:sb.toString().substring(0,sb.length()-1);
		return str;
	}
	
	public void setSignString(String str){
		this.signString = str;
	}
	
	
}
